package com.example.tb_base.base_activity_fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.tb_base.AnalysisPage

/**
 * Fragment基类，统一处理布局加载、页面统计等通用逻辑。
 * 子类只需实现抽象方法即可快速搭建自己的Fragment。
 */
abstract class BaseFragment : Fragment(), AnalysisPage {

    final override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return createView(inflater, container, savedInstanceState)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        onFragmentCreated(view, savedInstanceState)
    }

    protected abstract fun layoutId(): Int
    protected abstract fun onFragmentCreated(view: View, savedInstanceState: Bundle?)
    protected fun rootView(): View? = view
    final override fun getPageName(): String = javaClass.simpleName
    protected open fun createView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(layoutId(), container, false)
    }
}